<?php

namespace app\adminapi\controller\system;

use app\adminapi\service\SysRoleService;
use app\adminapi\service\SysUserService;
use app\adminapi\validate\SysUserValidate;
use app\common\controller\BaseAdminController;

class SysUserController extends BaseAdminController
{
    public array $notNeedLogin = [];

    public function list()
    {
        $params = (new SysUserValidate())->get()->goCheck('list');
        $list = (new SysUserService())->list($params);
        return app('json')->successWithData($list);
    }

    /**
     * @title   新增角色
     * @businessType    INSERT
     */
    public function insert()
    {
        $params = (new SysUserValidate())->post()->goCheck('insert');
        (new SysUserService())->addSysUser($params);
        return app('json')->success();
    }

    /**
     * @title   删除用户
     * @businessType    DELETE
     */
    public function delete()
    {
        $params = (new SysUserValidate())->delete()->goCheck('delete');
        $result = (new SysUserService())->deleteSysUser($params['userId']);
        return app('json')->successWithData($result);
    }

    public function query()
    {
        $params = (new SysUserValidate())->get()->goCheck('query');
        $result = (new SysUserService())->getSysUser($params['userId']);
        return app('json')->successWithData($result);
    }

    /**
     * @title   更新用户
     * @businessType    UPDATE
     */
    public function update()
    {
        $params = (new SysUserValidate())->put()->goCheck('update');
        $result = (new SysUserService())->updateSysUser($params);
        return app('json')->successWithData($result);
    }

    /**
     * @title   修改用户状态
     * @businessType    UPDATE
     */
    public function changeStatus()
    {
        $params = (new SysUserValidate())->put()->goCheck('changeStatus');
        $result = (new SysUserService())->changeSysUserStatus($params);
        return app('json')->successWithData($result);
    }

    /**
     * @title   重置密码
     * @businessType    UPDATE
     */
    public function resetPwd()
    {
        $params = (new SysUserValidate())->put()->goCheck('resetPwd');
        $result = (new SysUserService())->resetPwd($params);
        return app('json')->successWithData($result);
    }
}